package com.tianji.learning.mq;

import com.tianji.common.constants.MqConstants;
import com.tianji.learning.enums.PointsRecordType;
import com.tianji.learning.mq.msg.SignInMessage;
import com.tianji.learning.service.IPointsRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author liuchun
 * @version 1.0
 * @date 2024/9/8 17:10
 */
@Component
@Slf4j
public class SignPointsListener {

    @Autowired
    private IPointsRecordService recordService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value= "sign.points.queue",durable = "true"),
            exchange = @Exchange(name = MqConstants.Exchange.LEARNING_EXCHANGE,type = ExchangeTypes.TOPIC),
            key = MqConstants.Key.SIGN_IN
    ))
    public void ListenSignMessage(SignInMessage message){
        log.debug("接收到积分消息，{}",message);
        recordService.addPointsRecord(message, PointsRecordType.SIGN);
    }
}
